// import Navigo from 'navigo'
// import request from 'browser-request'
// import { bb } from 'billboard.js'
(() => {
  const ysums = {
      "1803":62564,   "1804":153566,  "1805":333009,  "1806":402385,
      "1807":330189,  "1808":356270,  "1809":425329,  "1810":108614,
      "1811":348244,  "1812":381222,  "1813":161795,  "1814":108473,
      "1815":305119,  "1817":427729,  "1818":198569,  "1819":712493,
      "1820":689939,  "1821":463673,  "1822":537909,  "1823":445485,
      "1824":455693,  "1825":447602,  "1826":486482,  "1827":373460,
      "1828":532269,  "1830":874749,  "1831":1470204, "1832":1190538,
      "1833":1181035, "1834":1032310, "1835":1054982, "1836":1022833,
      "1837":935591,  "1838":839888,  "1839":1129887, "1840":818502,
      "1841":864783,  "1842":1280028, "1843":1279540, "1844":529506,
      "1845":1345670, "1846":1332471, "1847":1470461, "1848":1036179,
      "1849":1092956, "1850":1060357, "1851":695420,  "1852":1215679,
      "1853":1223364, "1854":1574921, "1855":1246761, "1856":1202209,
      "1857":1398635, "1858":1270616, "1859":763606,  "1860":1377844,
      "1861":1310968, "1862":936073,  "1863":1186806, "1864":1023442,
      "1865":994230,  "1866":984449,  "1867":1535069, "1868":979254,
      "1869":1435839, "1870":1493402, "1871":1525131, "1872":1047035,
      "1873":1150867, "1874":770763,  "1875":1320932, "1876":1423104,
      "1877":1206528, "1878":1631899, "1879":1229900, "1880":1231870,
      "1881":1875252, "1882":1377694, "1883":2417655, "1884":1724323,
      "1885":1138262, "1886":1981644, "1887":2955797, "1888":2719001,
      "1889":1829895, "1890":1996446, "1891":472110,  "1892":1141106,
      "1893":1165521, "1894":1149626, "1895":1498549, "1896":1719063,
      "1897":1461291, "1898":1561329, "1899":1342773, "1900":1935998,
      "1901":1321952, "1902":2705084, "1903":994191,  "1904":1195586,
      "1905":1087716, "1906":1766904, "1907":1496225, "1908":1896247,
      "null":27555
    }

  const data = [
    0,          126,            8,          5,
    14,         4,              43,         0,
    22,         33,             20,         0,
    94,         52,             222,        90,
    72,         15,             150,        18,
    65,         127,            41,         90,
    42,         52,             367,        212,
    1080,       184,            159,        351,
    247,        297,            328,        48,
    95,         541,            152,        125,
    227,        362,            219,        263,
    82,         300,            96,         399,
    210,        287,            385,        149,
    174,        195,            170,        359,
    431,        188,            705,        406,
    319,        587,            561,        183,
    646,        268,            977,        303,
    182,        178,            769,        497,
    472,        560,            372,        1717,
    3618,       5570,           3480,       2835,
    1483,       2863,           18255,      19660,
    19672,      21626,          2398,       1017,
    2063,       2097,           938,        1751,
    828,        1713,           1559,       1175,
    1523,       4688,           700,        1157,
    1756,       1363,           880,        2325,
  ]

  function loadchart() {
    const bindto = '#chart'
    const data =  {
      "x": "x-axis",
      "columns": [],
      "type": "area-spline"
    }
    return bb.generate({
      data, bindto, "point": { "show": true, "r" : 2 },
    })
  }

  function makechart(data, ysums) {

    const years = Object
      .keys(ysums)
      .map(x => parseInt(x))
      .sort()
    const ymap = (c, i) => 10000 * c / ysums[years[i]]
    const x = ['x-axis', ...years]
    const y = [`per 10,000 words`,...data.map(ymap)]
    const chart = loadchart()
    
    chart.load({ columns : [x, y] })
  }

  makechart(data, ysums)
  console.log(bb)

})()